package com.etc.controller;

import ch.qos.logback.core.net.SyslogOutputStream;
import com.etc.entity.User;
import com.etc.service.UserService;
import com.etc.util.CommonMessage;
import com.etc.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2019/5/21.
 */
@RestController
@RequestMapping(value = "userapi")
public class UserController {
    /**
     * 分页查询（李添杭）
     */
    @Autowired
    private UserService userService;
    @GetMapping(value = "list")
    public PageData<User> listUser(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "limit", defaultValue = "10") Integer limit, @RequestParam(value = "content", required = false, defaultValue = "") String content) {
        PageData<User> pd = userService.getPageData(page - 1, limit, content);
        pd.setCode(0);
        return pd;
    }

    /**
     * 用户更新（李添杭）
     * @param user
     * @return
     */
    @PutMapping(value = "update")
    public CommonMessage updageUser(@RequestBody User user) {

        boolean flag = userService.updateUser(user);
        CommonMessage cm = new CommonMessage("修改成功");
        if (!flag) {

            cm.setMsg("修改失败");
        }
        return cm;
    }


}
